package com.tn.controller.truck;

import cn.hutool.core.util.StrUtil;
import com.gitee.hifong45.FE;
import com.gitee.hifong45.Kv;
import com.gitee.hifong45.Ret;
import com.tn.annotation.LogRequestInfo;
import com.tn.controller.alarm.common.model.truck.BindTruckDto;
import com.tn.controller.alarm.common.model.truck.JsonWhiteBean;
import com.tn.controller.alarm.common.model.truck.TruckDO;
import com.tn.service.truck.TruckService;
import com.tn.vo.TruckInfoMinVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Info;
import lombok.var;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/aucy")
public class TruckController {

    @Resource
    TruckService truckService;

    @GetMapping("/getTruckByCardId")
    public Ret<Object> getTruckInfo(String cardId) {
        if(StrUtil.isNotBlank(cardId)) {
            TruckDO ret = truckService.getTruckInfoByCardId(cardId);
            return Ret.Ok(ret);
        }
        // 无cardId，则查全部
        var ret = truckService.getTruckAndTag();
        return Ret.Ok(ret);
    }

    @GetMapping("/setTruckAndCardId")
    public Ret<Object> setTruckAndCard(String cardId, String license) {
        truckService.setTruckAndCardId(cardId, license);
        return Ret.Ok();
    }

    @GetMapping("/truckinwhite")
    public Ret<Object> truckInWhiteList(String license) {
        FE.nullThrow(license, "license");
        Kv ret = truckService.checkTruckInWhiteList(license);
        return Ret.Ok(ret);
    }

    @GetMapping("/truck/working")
    public Ret<List<TruckInfoMinVo>> getWorkingTruck() {
        var ret = truckService.getWorkingTruck();
        return Ret.Ok(ret);
    }

    @GetMapping("/truck/setstatus")
    public Ret<Kv> setTruckOutGate(String license, String taskNo, Integer status) {
        var ret = truckService.setTruckOutGate(license, taskNo, status);
        return Ret.Ok(ret);
    }

    @GetMapping("/truck/do")
    public Ret<Object> updateTruckInfo(String type, String license, String taskNo) {
        // type = c, r, u
        if(type.equalsIgnoreCase("c")) {
            return Ret.Ok();
        }

        if(type.equalsIgnoreCase("r")) {

            return Ret.Ok();
        }

        if(type.equalsIgnoreCase("u")) {
            return Ret.Ok();
        }

        return Ret.Ok(Kv.of("type", type, "license", license));
    }



    /**
     * 查询当前未解绑的车辆列表
     * @return
     */
    @GetMapping("/getBindInfoLicense")
    public Ret<Object> getBindInfoLicense() {
        List<BindTruckDto> ret = truckService.getBindInfoLicense();
        return Ret.Ok(ret);
    }
//    /**
//     *本地查询任务信息
//     */
//    @LogRequestInfo
//    @RequestMapping("/truck/getBillPoundMap")
//    public Ret<Object> getBillPoundMap(@RequestBody JsonWhiteBean json) {
//        JsonWhiteBean.DataDTO data = json.getData();
//        String license = data.getCarNo();
//        return Ret.Ok(truckService.getBillPoundMap(license));
//    }
    /**
     *本地查询任务信息
     */
    @LogRequestInfo
    @RequestMapping("/truck/getBillPoundMap")
    public Map getBillPoundMap(@RequestBody JsonWhiteBean json) {
        JsonWhiteBean.DataDTO data1 = json.getData();
        String license = data1.getCarNo();
        Map map = new HashMap();
        map.put("info", "操作成功");
        map.put("status", "1");

        Map data = new HashMap();
        data.put("poundBill", truckService.getBillPoundMap(license));
        map.put("data", data);
        return map;
    }
}
